import { getUnitListAll } from '@/api/collection/unit'
import { getLabelList } from '@/api/energyCompare/energyLibrary'
import { BasicColumn, FormSchema } from '@/components/Table'
import { timeDimensionOptions } from '../energyLibrary/data'
import { getClassifyTree } from '@/api/collection/classify'
import dayjs from 'dayjs'

export const searchFormSchema: FormSchema[] = [
  {
    field: 'deviceId1',
    label: '设备 1',
    slot: 'deviceId1',
    colProps: { span: 5 },
  },
  {
    field: 'deviceId2',
    label: '设备 2',
    slot: 'deviceId2',
    colProps: { span: 5 },
  },
  {
    field: 'timeDimension',
    label: '时间维度',
    component: 'Select',
    colProps: { span: 5 },
    defaultValue: 1,
    componentProps: ({ formModel, formActionType }) => {
      return {
        options: timeDimensionOptions,
        onChange: (val) => {
          const { valueFormat, picker } = timeDimensionOptions.filter((item) => item.value === val)[0]
          formModel.date = dayjs()
          const { updateSchema } = formActionType
          updateSchema({
            field: 'date',
            componentProps: {
              picker,
              valueFormat,
            },
          })
        },
      }
    },
  },
  {
    field: 'date',
    label: '时间维度',
    component: 'DatePicker',
    colProps: { span: 5 },
    defaultValue: dayjs(),
    componentProps: {
      picker: 'year',
      valueFormat: 'YYYY',
    },
  },
]

export const columns = [
  {
    title: '指标名称',
    dataIndex: 'dataTypeName',
  },
  {
    title: '单位',
    dataIndex: 'dataUnitName',
    width: 100,
  },
  {
    title: '时间维度',
    dataIndex: 'timeDimension',
    width: 80,
    customRender: ({ text }) => {
      return timeDimensionOptions.find((item) => item.value === text)?.label
    },
  },
  {
    title: '标杆值',
    dataIndex: 'standard',
    width: 120,
    editRow: true,
    editComponent: 'InputNumber',
    editRender: ({ text }) => {
      return text === null ? '--' : text
    },
  },
  {
    title: '实际值-设备 1',
    dataIndex: 'deviceVal1',
  },
  {
    title: '差值-设备 1',
    dataIndex: 'deviceValDiff1',
  },
  {
    title: '实际值-设备 2',
    dataIndex: 'deviceVal2',
  },
  {
    title: '差值-设备 2',
    dataIndex: 'deviceValDiff2',
  },
] as BasicColumn[]
